<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>

<table border="1"  style="px;width:500px;height: 200px;border-collapse: collapse;text-align: center;">
	<tr >
		<td>产品ID</td>
		<td>产品名字</td>
		<td>产品描述</td>
		<td>产品价格</td>
		<td>操作</td>

	</tr>
	{foreach name="list" item="val" key="i"}
	
	<tr name="product_list[{$i}]">
		<td id="product_id[{$i}]">{$val.product_id}</td>
		<td name="product_name[{$i}]">{$val.product_name}</td>
		<td name="product_information[{$i}]">{$val.product_information}</td>
		<td name="product_price[{$i}]">{$val.product_price}</td>
		<td><button onclick="add{$i}(this)" >加入购物车</button></td>
	</tr>

	<script type="text/javascript" src="/static/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
	function add{$i}(obj){

		var product_id=document.getElementById("product_id[{$i}]").innerHTML;
		
		
		var formdata = new FormData();
		
		$.ajax({
			type:'post',
			url:'/test/product/ajax',
			data:{'product_id':product_id},
			dataType:'json',
	        success : function(ret){
	        	console.log(ret);
	        	alert(ret);
	        	
	        	
	        
	   

	        },
	        error : function(){ console.log(2222);}
		})

	};
</script>
	{/foreach}
</table>
</body>

</html>